package map;

import java.util.*;
import java.util.function.Consumer;

public class MapTest2 {
    public static void main(String[] args) {
//        省份城市的，省份是String,List里装的是城市
        HashMap<String, List<String>> map=new HashMap<>();
        ArrayList<String> list1=new ArrayList<>();
        Collections.addAll(list1,"南京市","扬州市","苏州市","无锡市","常州市");
        ArrayList<String> list2=new ArrayList<>();
        Collections.addAll(list2,"武汉市","荆州市","黄石市","黄冈市");
        ArrayList<String> list3=new ArrayList<>();
        Collections.addAll(list3,"赣州市","九江市","南昌市","抚州市");
        System.out.println(list1);
        System.out.println(list2);
        System.out.println(list3);
        map.put("江苏省",list1);
        map.put("湖北省",list2);
        map.put("江西省",list3);
        System.out.println(map);
        Set<Map.Entry<String,List<String>>> entrySet=map.entrySet();
        for (Map.Entry<String, List<String>> stringListEntry : entrySet) {
//            键是省份
            String key=stringListEntry.getKey();
//            System.out.print是没有换行的
            System.out.print(key+"=");
//            市是列表list
            List<String> list=stringListEntry.getValue();
            for (int i = 0; i < list.size()-1; i++) {
                System.out.print(list.get(i)+",");
            }
//            System.out.println是有换行的
            System.out.println(list.get(list.size() - 1));
        }
    }
}
